const path = require('path');
const isDev = think.env === 'development';
const kcors = require('kcors');
// const bodyParser = require('koa-bodyparser');
const fixContentEncoding = require('../middleware/fix-content-encoding.js');
// const compression = require('compression');

module.exports = [
  {
    handle: kcors, // 处理跨域
    options: {},
  },
  {
    handle: fixContentEncoding, // 添加自定义中间件来修复 Content-Encoding
    options: {},
  },
  {
    handle: 'meta',
    options: {
      logRequest: isDev,
      sendResponseTime: isDev,
    },
  },
  {
    handle: 'resource',
    enable: true,
    options: {
      root: path.join(think.ROOT_PATH, 'www'),
      publicPath:
        /^\/(static|css|images|cert|favicon\.ico|MP_verify_pGnyV6LfXyToYs7u\.txt)/,
    },
  },
  {
    handle: 'trace',
    enable: !think.isCli,
    options: {
      debug: isDev,
    },
  },
  {
    handle: 'payload',
    options: {},
  },
  {
    handle: 'router',
    options: {
      defaultModule: 'index',
      defaultController: 'job',
      defaultAction: 'index',
    },
  },
  // {
  //   handle: bodyParser,
  //   options: {
  //     jsonLimit: '5mb',
  //     formLimit: '5mb',
  //     textLimit: '5mb',
  //     enableTypes: ['json', 'form', 'text'],
  //     encoding: 'utf-8',
  //   }
  // },
  // {
  //   handle: compression,
  //   options: {
  //     // 配置选项
  //   }
  // },
  'logic',
  'controller',
];
